module.exports = function (app, mongoose, multer, fs) {
  // 配置保存路径
  var upload = multer({
    dest: 'public/images'
  });

  app.post('/upload', upload.single('file'), function (req, res, next) {
    //上传的文件在files里
    // 原文件名称
    // var newName = `${req.file.destination}/${req.file.originalname}`
    //随机名称
    var newName = `${req.file.path}.jpg`
    fs.rename(req.file.path, newName, function (err) {
      console.log(req.file)
      if (err) {
        res.send(err);
      } else {
        res.send({
          status: 1,
          imageUrl: `http://127.0.0.1:8080/${newName}`
        })
        return
      }
    });
  })
}
